package com.atguigu.daijia.driver.controller;

import com.atguigu.daijia.common.longin.JiyunLogin;
import com.atguigu.daijia.common.result.Result;
import com.atguigu.daijia.common.util.AuthContextHolder;
import com.atguigu.daijia.driver.service.LocationService;
import com.atguigu.daijia.model.form.map.OrderServiceLocationForm;
import com.atguigu.daijia.model.form.map.UpdateDriverLocationForm;
import com.atguigu.daijia.model.form.map.UpdateOrderLocationForm;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.checkerframework.checker.nullness.qual.KeyForBottom;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@Tag(name = "位置API接口管理")
@RestController
@RequestMapping(value="/location")
@SuppressWarnings({"unchecked", "rawtypes"})
public class LocationController {
	
    @Autowired
    private LocationService locationService;

    @Operation(summary = "开启接单服务，更新司机的地理位置坐标")
    @JiyunLogin
    @PostMapping("/updateDriverLocation")
    public Result<Boolean> updateDriverLocation(@RequestBody UpdateDriverLocationForm updateDriverLocationForm){
        Long userId = AuthContextHolder.getUserId();
        updateDriverLocationForm.setDriverId(userId);
        return Result.ok(locationService.updateDriverLocation(updateDriverLocationForm));
    }


    @Operation(summary = "关闭接单服务，删除司机的地理位置坐标")
    @JiyunLogin
    @DeleteMapping("/removeDriverLocation/{driverId}")
    public Result<Boolean> removeDriverLocation(@PathVariable("driverId") Long driverId){
        return Result.ok(locationService.removeDriverLocation(driverId));
    }

    @Operation(summary = "司机前往代驾地点，需要更新订单的地址到redis的缓存中，采用GE0计算")
    @JiyunLogin
    @DeleteMapping("/updateOrderLocationToCache")
    public Result<Boolean> updateOrderLocationToCache(@RequestBody UpdateOrderLocationForm updateOrderLocationForm) {
        return Result.ok(locationService.updateOrderLocationToCache(updateOrderLocationForm));
    }

    @Operation(summary = "开始代驾，保存代驾的订单位置gps")
    @PostMapping("/saveOrderServiceLocation")
    public Result<Boolean> saveOrderServiceLocation(@RequestBody List<OrderServiceLocationForm> orderServiceLocationFormList) {
        return Result.ok(locationService.saveOrderServiceLocation(orderServiceLocationFormList));
    }











}

